{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3cff0b93",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "```math\n",
      "P(X|Y)=\\frac{P(Y|X)P(X)}{P(Y)}\n",
      "```\n",
      "$$\n",
      "P(X|Y)=\\frac{P(Y|X)P(X)}{P(Y)}\n",
      "$$\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "有道云公式转markdown公式\n",
    "\"\"\"\n",
    "import argparse\n",
    "import re\n",
    "\n",
    "import pyperclip\n",
    "\n",
    " \n",
    "y2m_pat_block = r'```math((.|\\n)*?)```'\n",
    "y2m_pat_inline = r'`\\$(.*?)\\$`'\n",
    "\n",
    "src_content = pyperclip.paste()\n",
    "\n",
    "print(src_content)\n",
    "\n",
    "des_content = re.sub(y2m_pat_block, r'$$\\1$$', src_content)\n",
    "des_content = re.sub(y2m_pat_inline, r'$\\1$', des_content)\n",
    "\n",
    "print(des_content)\n",
    " \n",
    "pyperclip.copy(des_content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "93528249",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "$$\n",
      "P(X|Y)=\\frac{P(Y|X)P(X)}{P(Y)}\n",
      "$$\n",
      "```math\n",
      "P(X|Y)=\\frac{P(Y|X)P(X)}{P(Y)}\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "markdown转有道云公式公式\n",
    "\"\"\"\n",
    "\n",
    "import re\n",
    "import pyperclip\n",
    "\n",
    "m2y_pat_block = r'\\$\\$((.|\\n)*?)\\$\\$'\n",
    "m2y_pat_inline = r'(?<!`)\\$(.*?)\\$(?!`)'\n",
    "    \n",
    "    \n",
    "src_content = pyperclip.paste()\n",
    "\n",
    "print(src_content)\n",
    "\n",
    "des_content = re.sub(m2y_pat_block, r'```math\\1```', src_content)\n",
    "des_content = re.sub(m2y_pat_inline, r'`$\\1$`', des_content)\n",
    "\n",
    "print(des_content)\n",
    "\n",
    "pyperclip.copy(des_content) "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
